package com.friday.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.friday.dao.StockDao;
import com.friday.util.Trans;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StockController {

    @Autowired
    private StockDao stockDao;

    @RequestMapping("/plantList")
    public JSONArray getAllPlant(){
        return stockDao.getAllPlant();
    }

    @RequestMapping("/plantDetail")
    public JSONObject getPlantdtl(@RequestParam("id") int id){
        JSONObject plant=stockDao.getPlantById(id);
        plant.put("productStock",stockDao.getPlantProdByPId(id));
        plant.put("timeGraph",stockDao.getStockRecordByPId(id));
        plant.put("stockScore", Trans.stockScore(stockDao.getInstock(id),stockDao.getOutstock(id)));
        return plant;
    }

    @RequestMapping("/goodsPlantList")
    public JSONArray getProdStock(@RequestParam("id") int id){
        return stockDao.getProdStock(id);
    }


}
